package com.moyq5.mvc.maker.test.bean.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.PrePersist;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicUpdate;

/**
 * 设备信息扩展信息
 * @author Moyq5
 * @date 2018年5月2日
 */
@Entity
@Table(name = "iot_device_ext")
@DynamicUpdate
public class IotDeviceExt implements java.io.Serializable {

	private static final long serialVersionUID = 1L;
	/**
	 * 设备ID
	 */
	@Id
	@OneToOne
	@JoinColumn(name="device_id")
	private IotDevice device;
	/**
	 * 密钥
	 */
	@Column(name = "trans_key", length = 32, nullable = false, columnDefinition="varchar(32) default '00000000000000000000000000000000'")
	private String transKey;
	/**
	 * 通讯协议版本号
	 */
	@Column(name = "tcp_ver", nullable = false, precision = 3, scale = 0)
	private Integer tcpVer;
	/**
	 * 设备软件版本号
	 */
	@Column(name = "soft_ver", nullable = false, precision = 3, scale = 0)
	private Integer softVer;
	/**
	 * 目标连接服务器
	 */
	@ManyToOne(fetch = FetchType.LAZY, optional = true)
	@JoinColumn(name = "dst_server_id")
	private SysServer dstServer;
	/**
	 * 当前连接服务器
	 */
	@ManyToOne(fetch = FetchType.LAZY, optional = true)
	@JoinColumn(name = "cur_server_id")
	private SysServer curServer;
	/**
	 * 当前状态信息（包含各种状态）
	 * @see IotBrand#getState()
	 */
	@Column(name = "state", nullable = false, precision = 8, scale = 0)
	private Integer state;
	/**
	 * 当前信号强度
	 */
	@Column(name = "sign", nullable = false, precision = 3, scale = 0)
	private Integer sign;
	/**
	 * 当前剩余电量
	 */
	@Column(name = "elec", nullable = false, precision = 3, scale = 0)
	private Integer elec;
	@PrePersist
	public void prePersist() {
		if (null == transKey) {
			transKey = "00000000000000000000000000000000";
		}
		if (null == state) {
			state = 0;
		}
		if (null == elec) {
			elec = 0;
		}
		if (null == sign) {
			sign = 0;
		}
		if (null == softVer) {
			softVer = 0;
		}
		if (null == tcpVer) {
			tcpVer = 0;
		}
		
	}

	public IotDevice getDevice() {
		return device;
	}

	public void setDevice(IotDevice device) {
		this.device = device;
	}

	public SysServer getDstServer() {
		return dstServer;
	}

	public void setDstServer(SysServer dstServer) {
		this.dstServer = dstServer;
	}

	public SysServer getCurServer() {
		return curServer;
	}

	public void setCurServer(SysServer curServer) {
		this.curServer = curServer;
	}

	public String getTransKey() {
		return transKey;
	}

	public void setTransKey(String transKey) {
		this.transKey = transKey;
	}

	public Integer getTcpVer() {
		return tcpVer;
	}

	public void setTcpVer(Integer tcpVer) {
		this.tcpVer = tcpVer;
	}

	public Integer getSoftVer() {
		return softVer;
	}

	public void setSoftVer(Integer softVer) {
		this.softVer = softVer;
	}

	public Integer getSign() {
		return sign;
	}

	public void setSign(Integer sign) {
		this.sign = sign;
	}

	public Integer getElec() {
		return elec;
	}

	public void setElec(Integer elec) {
		this.elec = elec;
	}

	public Integer getState() {
		return state;
	}

	public void setState(Integer state) {
		this.state = state;
	}

}
